// 引入一级路由
// import Home from "@/pages/Home/index.vue";
// import Login from "@/pages/Login";
// import Register from "@/pages/Register";
// import Search from "@/pages/Search";
import Test from "@/pages/Test/test.vue"; //测试路由
// import Detail from "@/pages/Detail";
// import AddCart from "@/pages/AddCartSuccess/addCartSuccess.vue";
// import ShopCart from "@/pages/ShopCart/shopCart.vue";
// import Trade from "@/pages/Trade/trade";
// import Pay from "@/pages/Pay/pay";
// import PaySuccess from "@/pages/PaySuccess";
// // import Center from "@/pages/Center";

// 引入二级路由
// import MyOrder from "@/pages/Center/myOrder/myOrder";
// import GroupOrder from "@/pages/Center/groupOrder/groupOrder";

let routes = [
  {
    path: "/center",
    component: () => import("@/pages/Center"),
    meta: { show: true },
    children: [
      {
        path: "myOrder",
        component: () => import("@/pages/Center/myOrder/myOrder"),
      },
      {
        path: "groupOrder",
        component: () => import("@/pages/Center/groupOrder/groupOrder"),
      },
      {
        path: "/center",
        redirect: "/center/myOrder",
      },
    ],
  },
  {
    path: "/home",
    component: () => import("@/pages/Home/index.vue"),
    meta: { show: true },
  },
  {
    path: "/paysuccess",
    component: () => import("@/pages/PaySuccess"),
    meta: { show: true },
  },
  {
    path: "/trade",
    component: () => import("@/pages/Trade/trade"),
    meta: { show: true },
    beforeEnter: (to, from, next) => {
      // form.path == '/pay' 是为了返回的时候可以回去
      if (from.path == "/shopCart" || from.path == "/pay") {
        next();
      } else {
        /* 
         false: 取消当前的导航。如果浏览器的 URL 改变了(可能是用户手动或者浏览器后退按钮)，
         那么 URL 地址会重置到 from 路由对应的地址。
        */
        next(false);
      }
    },
  },
  {
    path: "/pay",
    component: () => import("@/pages/Pay/pay"),
    meta: { show: true },
    beforeEnter: (to, from, next) => {
      if (from.path == "/trade" || from.path == "/paysuccess") {
        next();
      } else {
        next(false);
      }
    },
  },
  {
    path: "/test",
    component: Test,
    meta: { show: true },
  },
  {
    path: "/login",
    component: () => import("@/pages/Login"),
    meta: { show: false },
  },
  {
    path: "/register",
    component: () => import("@/pages/Register"),
    meta: { show: false },
  },
  {
    //params传参方式 后面加 ？ 表示可传可不传
    path: "/search/:keyword?",
    name: "Search",
    component: () => import("@/pages/Search"),
    meta: { show: true },
  },
  {
    path: "/detail/:goodsid",
    component: () => import("@/pages/Detail"),
    meta: { show: true },
  },
  {
    path: "/addCart",
    component: () => import("@/pages/AddCartSuccess/addCartSuccess.vue"),
    meta: { show: true },
  },
  {
    path: "/shopCart",
    component: () => import("@/pages/ShopCart/shopCart.vue"),
    meta: { show: true },
  },
  {
    path: "*",
    redirect: "/home",
  },
];

export default routes;
